package com.jshx.sz.gdjt.control;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jshx.sz.gdjt.R;

/**
 * 页面标题头
 * @author xiangchangan
 * @time 2013-08-20
 */
public class HeaderView extends RelativeLayout {

	private final static String TAG = "HeaderView";
	
	/**
	 * 左边按钮
	 */
	private Button left;
	
	/**
	 * 右边按钮
	 */
	private Button right;
	
	/**
	 * 标题
	 */
	private TextView title;
	
	/**
	 * 上下文对象
	 */
	private Context context;
	
	public HeaderView(Context context) {
		super(context);
		this.context = context;
	}
	
	public HeaderView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.context = context;
	}

	@Override
	protected void onFinishInflate() 
	{
		super.onFinishInflate();
		left = (Button)findViewById(R.id.header_buttonleft);
		right = (Button)findViewById(R.id.header_buttonright);
		title = (TextView)findViewById(R.id.header_title);
	}
	
	/**
	 * 设置标题
	 */
	public void setTitle(String text)
	{
		if(title != null && text != null)
		{
			title.setText(text);
		}
	}
	
	/**
	 * 左边按钮点击监听
	 */
	public void setLeftButtonClickListener(OnClickListener l, int back_res, String text)
	{
		if(l != null && left != null)
		{
			left.setText(text);
			left.setVisibility(View.VISIBLE);
			left.setBackgroundResource(back_res);
			left.setOnClickListener(l);
		}
	}
	
	/**
	 * 右边按钮点击监听
	 */
	public void setRightButtonClickListener(OnClickListener l, int back_res, String text)
	{
		if(l != null && right != null)
		{
			right.setText(text);
			right.setVisibility(View.VISIBLE);
			right.setBackgroundResource(back_res);
			right.setOnClickListener(l);
		}
	}
}
